package com.mayikt.member.impl.mapper;


import com.mayikt.member.impl.entitydo.UserLoginLogDo;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

public interface UserLoginLogMapper {

    @Insert("INSERT INTO user_login_log VALUES (null, #{userId}, #{loginIp}, now(), #{loginToken}, #{channel}, #{equipment}, 1)")
    int insertUserLoginLog(UserLoginLogDo userLoginLogDo);

    @Select("SELECT id           AS id,\n" +
            "       user_id      AS userid,\n" +
            "       login_time   AS logintime,\n" +
            "       login_token  AS logintoken,\n" +
            "       channel      AS channel,\n" +
            "       equipment    AS equipment,\n" +
            "       is_available AS isavailable\n" +
            "FROM user_login_log\n" +
            "WHERE channel = #{channel}\n" +
            "  AND user_id = #{userId}\n" +
            "  AND is_available = 1")
    UserLoginLogDo selectByUserIdAndLoginType(@Param("userId") Long userId, @Param("channel") String channel);

    @Update("update user_login_log set is_available=0 where login_token=#{loginToken}")
    int updateUserTokenNotQuipment(@Param("loginToken") String loginToken);
}
